package com.mg.admin.service.admin.impl;

import com.mg.admin.bean.admin.DictVO;
import com.mg.admin.dao.admin.DictMapper;
import com.mg.admin.page.PageBean;
import com.mg.admin.page.PageParam;
import com.mg.admin.service.admin.DictService;
import com.xiaoleilu.hutool.lang.Dict;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DictServiceImpl implements DictService {

	@Autowired
	private DictMapper dictMapper;


	@Override
	public List<DictVO> findAll() {
		List<DictVO> list = dictMapper.findAll();
		return list;
	}


	@Override
	@Transactional
	public DictVO insertOne(DictVO dictVO) {
		dictMapper.insertOne(dictVO);
		return dictVO;
	}

	@Override
	@Transactional
	public DictVO updateOne(DictVO dictVO) {
		dictMapper.updateOne(dictVO);
		return dictVO;
	}


	@Override
	public List<DictVO> findByClassId(Long classId) {
		List<DictVO> list = dictMapper.findByClassId(classId);
		return list;
	}

	@Override
	public PageBean queryForPage(DictVO dictVO,PageParam pageParam) {
		RowBounds rb = new RowBounds(pageParam.getStart(),pageParam.getNumPerPage());
		List<DictVO> list = dictMapper.queryForPage(dictVO,rb);
		int totalCount = dictMapper.queryCountForPage(dictVO);
		PageBean pageBean = new PageBean(pageParam.getCurrentPage(),pageParam.getNumPerPage(),totalCount,list);
		return pageBean;
	}

	@Override
	@Transactional
	public void delete(Long id) {
		dictMapper.delete(id);
	}

	@Override
	@Transactional
	public void detailInsertOne(DictVO dictVO) {
		dictMapper.detailInsertOne(dictVO);
	}

	@Override
	@Transactional
	public void detailUpdateOne(DictVO dictVO) {
		dictMapper.detailUpdateOne(dictVO);
	}

	@Override
	public DictVO findDetailById(Long id) {
		DictVO dictVO = dictMapper.findDetailById(id);
			return dictVO;
	}

	@Override
	public void detaildelete(Long id) {
		dictMapper.detaildelete(id);
	}


}
